package com.jhg.drgclinicalpathway.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface QingdanDao {

    /**
     * 获取病人信息
     */
    @Select({
            "<script>",
            "select top 1 a.病人姓名 as XM,a.住院号 as BSH,a.年龄 NL,a.性别 as XB,\n" +
            " a.科室 as KSMC,a.医生 as ZYYS,a.入院日期 as RYRQ,a.出院日期 as CYRQ, " +
            " a.床日 CR, a.标准床日 BZCR ,a.病组编码 FZBM,a.病组名称 FZMC,a.总费用 BRZYF,a.标准总费用 BZZFY \n" +
            " from [dbo].[VDCP_病人信息_路径指标参考] a where 病人ID=#{jzh}",
            "</script>"
    })
    public List<Map<String, Object>> getBrxxByJzh(@Param("jzh") String id);

    /**
     * 获取病人诊断信息
     * @param id
     * @return
     */
    @Select({
            "<script>",
            "select a.ZDCX XH,a.JBBM,a.ZDMS,(case b.bfz  when 1 then 'MCC' when 2 then 'CC' else '' end) bfz from TMP_诊断信息 a left join YB_CHS_BFZML b on a.jbbm=b.jbbm " +
            " where JZH=#{jzh} and jlly=3 and zdlxid=3 order by cast(a.zdcx as int)" +
            "</script>"
    })
    public List<Map<String, Object>> getBrZdxxByJzh(@Param("jzh") String id);

    /***
     * 获取病人手术信息
     * @param id
     * @return
     */
    @Select({
            "<script>",
            " select top 20 * from TMP_手术信息 where JZH=#{jzh} order by sscx",
            "</script>"
    })
    public List<Map<String, Object>> getBrSsxxByJzh(@Param("jzh") String id);

    /**
     * 获取病人费用信息
     * @param id
     * @return
     */
    @Select({
            "<script>",
            " select a.结算时间 JSSJ,b.XMMC,sum(B.SL) SL,b.SRXM,b.DW,b.DJ,sum(b.ZJE) ZJE from VDCP_入组结算明细 a,TMP_费用信息 b \n" +
            " where a.就诊号=b.jzh and b.jzh=#{jzh} group by a.结算时间,b.SRXM,b.XMMC,b.DW,b.DJ order by SRXM",
            "</script>"
    })
    public List<Map<String, Object>> getBrFyxxByJzh(@Param("jzh") String id);

    /***
     * 获取诊断对应费用信息
     * @param id
     * @return
     */
    @Select({
            "<script>",
            " select a.结算时间 JSSJ,b.XMMC,sum(B.SL) SL,b.SRXM,b.DW,b.DJ,sum(b.ZJE) ZJE from VDCP_入组结算明细 a,TMP_费用信息 b \n" +
            " where a.就诊号=b.jzh and b.jzh=#{jzh} group by a.结算时间,b.SRXM,b.XMMC,b.DW,b.DJ order by SRXM",
            "</script>"
    })
    public List<Map<String, Object>> getZDFyxxByJzh(@Param("jzh") String id);

    /****
     * 获取医保结算记录
     * @param id
     * @return
     */
    @Select({
            "<script>",
            " select a.倍率 BL,a.结算时间 JSSJ, a.医保范围金额 YBFW,a.DRG权重 QZ,a.DdRG标准支付金额 BZZF,a.基金支付比例 JJBL,a.项目结算基金支付 XMJS,a.医保基金DRG支付 YBDRGZF,a.盈亏状况 YKZT\n" +
            " from VDCP_入组结算明细 a where a.就诊号=#{jzh} ",
            "</script>"
    })
    public List<Map<String, Object>> getYbjsjlByJzh(@Param("jzh") String id);

    @Select({
            "<script>",
            " select a.编码 BM,a.名称 MC,a.提示信息 TS from [dbo].[jc_清单规则目录] a " +
            " left join [LJ_病人清单校验] b on a.id=b.清单ID where a.有效标志=1 and b.病人标识=#{jzh} ",
            "</script>"
    })
    public List<Map<String, Object>> getQDjyxxByJzh(@Param("jzh") String id);
}